package com.industrial.im.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.im.domain.YsXxTs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.im.domain.DispatchKeyItemManagement;
import com.industrial.im.service.IDispatchKeyItemManagementService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 重点事项管理Controller
 *
 * @author SangGuangCan
 * @date 2024-03-08
 */
@RestController
@RequestMapping("/keyItem")
public class DispatchKeyItemManagementController extends BaseController
{
    @Autowired
    private IDispatchKeyItemManagementService dispatchKeyItemManagementService;

    /**
     * 查询重点事项管理列表
     */
    @RequiresPermissions("keyItem:keyItem:list")
    @GetMapping("/list")
    public TableDataInfo list(DispatchKeyItemManagement dispatchKeyItemManagement)
    {
        startPage();
        List<DispatchKeyItemManagement> list = dispatchKeyItemManagementService.selectDispatchKeyItemManagementList(dispatchKeyItemManagement);
        return getDataTable(list);
    }

    /**
     * 导出重点事项管理列表
     */
    @RequiresPermissions("keyItem:keyItem:export")
    @Log(title = "重点事项管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DispatchKeyItemManagement dispatchKeyItemManagement)
    {
        List<DispatchKeyItemManagement> list = dispatchKeyItemManagementService.selectDispatchKeyItemManagementList(dispatchKeyItemManagement);
        ExcelUtil<DispatchKeyItemManagement> util = new ExcelUtil<DispatchKeyItemManagement>(DispatchKeyItemManagement.class);
        util.exportExcel(response, list, "重点事项管理数据");
    }

    /**
     * 获取重点事项管理详细信息
     */
    @RequiresPermissions("keyItem:keyItem:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(dispatchKeyItemManagementService.selectDispatchKeyItemManagementByBaseId(baseId));
    }

    /**
     * 新增重点事项管理
     */
    @RequiresPermissions("keyItem:keyItem:add")
    @Log(title = "重点事项管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DispatchKeyItemManagement dispatchKeyItemManagement)
    {
        return toAjax(dispatchKeyItemManagementService.insertDispatchKeyItemManagement(dispatchKeyItemManagement));
    }


    @GetMapping("getYsXxts")
    public AjaxResult getYsXxts(){
        String userId = SecurityUtils.getUserId();
        List<YsXxTs> ysXxts = dispatchKeyItemManagementService.getYsXxts(userId);
        return AjaxResult.success(ysXxts);
    }

    @GetMapping("clearYsXxts")
    public AjaxResult clearYsXxts(){
        String userId = SecurityUtils.getUserId();
        dispatchKeyItemManagementService.clearYsXxts(userId);
        return AjaxResult.success();
    }

    @PostMapping("/cuiBao")
    public AjaxResult cuiBao(@RequestBody Map<String,String> params){
        return dispatchKeyItemManagementService.cuiBao(params);
    }

    /**
     * 修改重点事项管理
     */
    @RequiresPermissions("keyItem:keyItem:edit")
    @Log(title = "重点事项管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DispatchKeyItemManagement dispatchKeyItemManagement)
    {
        return toAjax(dispatchKeyItemManagementService.updateDispatchKeyItemManagement(dispatchKeyItemManagement));
    }

    /**
     * 删除重点事项管理
     */
    @RequiresPermissions("keyItem:keyItem:remove")
    @Log(title = "重点事项管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseId}")
    public AjaxResult remove(@PathVariable String baseId)
    {
        return toAjax(dispatchKeyItemManagementService.deleteDispatchKeyItemManagementByBaseIds(baseId));
    }

    /**
     * 验收
     * @param params
     * @return
     */
    @PostMapping("/check")
    public AjaxResult check(@RequestBody DispatchKeyItemManagement params){
        dispatchKeyItemManagementService.check(params);
        return AjaxResult.success();
    }
}
